import defaltImg from '@/assets/images/load.gif'
import { useIntersectionObserver } from '@vueuse/core'
export default {
  install (app) {
    app.directive('imgLazy', {
      // bind (el, binding, vnode) {
      //   el.style.arg = binding.value.arg
      // }
      mounted (el, binding) {
        // console.log(binding)
        const { stop } = useIntersectionObserver(
          el, ([{ isIntersecting }]) => {
            if (isIntersecting) {
              el.src = defaltImg
              // console.log(el.onerror)
              setTimeout(() => {
                el.src = binding.value
                // console.log(6666)
              }, 2000)
              el.onerror = function () {
                el.src = defaltImg
              }
              stop()
            }
          },
          { threshold: 0 }
        )
      }
    })
    // return { target }
  }
}
